﻿using BestTrader.Cms.Core.Extensions;
using BestTrader.Cms.ViewModels;
using BestTrader.Cms.ViewModels.WebApi;
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BestTrader.Cms.WebApi.Validation
{
    public class ModifyUserInfoModelValidation : AbstractValidator<ModifyUserInfoIntput>
    {
        public ModifyUserInfoModelValidation()
        {
            RuleFor(x => x.Id).NotNull().WithMessage("用户ID不能为空");
            RuleFor(x=>x.Mobile).NotNull().WithMessage("手机号不能为空");
            RuleFor(x => x.Mobile).Must(IsMobile).WithMessage("手机号码格式不正确");
            RuleFor(x => x.Email).Must(IsEmail).WithMessage("邮箱地址格式不正确");
        }

        private bool IsEmail(string arg)
        {
            if (arg.IsNullOrWhiteSpace())
            {
                return true;
            }
            if (arg.IsEmail())
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        private bool IsMobile(string arg)
        {
            if (arg.IsNullOrWhiteSpace())
            {
                return true;
            }
            if (arg.IsMobileNumber())
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }
}
